package com.jf.car.util;

import lombok.Getter;

import java.util.List;
@Getter
public class PageInfo {
    /**
     * 总条数
     */
    private Integer count;
    /**
     * 数据列表
     */
    private List<?> list;
    /**
     * 当前页
     */
    private Integer page;
    /**
     * 每页显示条数
     */
    private Integer pageSize;
    /**
     * 分页查询偏移值
     */
    private Integer offset;
    /**
     * 总页数
     */
    private Integer pages;
    /**
     * 是否有下一页
     * boolean类型的变量禁止以is开头
     */
    private Boolean hasNext;
    /**
     * 是否有上一页
     * */
    private Boolean hasPrev;

    public PageInfo() {
    }

    public PageInfo(Integer page, Integer pageSize) {
        this.page = page;
        this.pageSize = pageSize;
        this.offset=(page-1)*pageSize;
    }
    public void setPageData(List<?> list,Integer count){
        this.list = list;
        this.count = count;
        int pages = count/pageSize;
        if(count%pageSize>0){
            pages++;
        }
        this.pages = pages;
        this.hasNext = page < pages;
        this.hasPrev = page > 1;
    }


}
